package Competition;

import org.junit.Test;

import java.util.*;

/**
 * @BelongsProject: SeniorArchitect-LeetCode
 * @BelongsPackage: Competition
 * @Author: zhuangxiaoyan
 * @CreateTime: 2023-11-12  10:57
 * @Description: TODO
 * @Version: 1.0
 */
public class 高访问员工 {

    private int toTime(String s){
        int hour = Integer.parseInt(s.substring(0,2));
        int min = Integer.parseInt(s.substring(2,4));
        return hour * 60 + min;
    }


    public List<String> findHighAccessEmployees(List<List<String>> access_times) {
        HashMap<String, List<Integer>> map = new HashMap<>();
        for(List<String> access : access_times){
            map.computeIfAbsent(access.get(0), (id) -> new ArrayList<>()).add(toTime(access.get(1)));
        }

        List<String> res = new ArrayList<>();
        for(Map.Entry<String, List<Integer>> e : map.entrySet()){
            Collections.sort(e.getValue());
            for(int i = 2; i < e.getValue().size(); i++){
                if(e.getValue().get(i) - e.getValue().get(i - 2) < 60){
                    res.add(e.getKey());
                    break;
                }
            }
        }
        return res;
    }

    @Test
    public void test() {
        List<List<String>> lists = new ArrayList<>();

        List<String> list = new ArrayList<>();
        list.add("a");
        list.add("0549");
        lists.add(list);

        List<String> list1 = new ArrayList<>();
        list1.add("b");
        list1.add("0457");
        lists.add(list1);

        List<String> list2 = new ArrayList<>();
        list2.add("a");
        list2.add("0532");
        lists.add(list2);

        List<String> list3 = new ArrayList<>();
        list3.add("a");
        list3.add("0621");
        lists.add(list3);

        List<String> list4 = new ArrayList<>();
        list4.add("b");
        list4.add("0540");
        lists.add(list4);

        List<String> highAccessEmployees = findHighAccessEmployees(lists);
        // System.out.println("0549".compareTo("0457"));
    }
}
